<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<!--此页面是用来发布系统公告的，只有领导才可以发布。全局可见。   杨卓霖-->
<head>
    <meta charset="UTF-8">
    <title>公告管理</title>
    <!-- load css -->
    <link rel="stylesheet" type="text/css" href="myconfig/layui/css/layui.css" media="all">
    <!-- 加载js文件-->
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="myconfig/layui/layui.js"></script>
    <style>
        #notice{
            text-align: center;
            margin: 0 auto;
            width: 500px;
            height:700px;
        }
    </style>
</head>
<body>
<div id="notice">
<h2>发布公告:</h2><br>
<div class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <div class="layui-form-item">
        <label class="layui-form-label">公告标题:</label>
        <div class="layui-input-block">
            <input type="text" name="noticeTitle"  id="noticeTitle" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">请填写公告内容:</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="noticeContent" id="noticeContent"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*" onclick="submitNotice()" shiro:hasPermission="add_notice">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</div>
</div>
<script>
    layui.use('form', function(){
        var form = layui.form;
        //各种基于事件的操作，下面会有进一步介绍
    });
    function submitNotice() {
        $.ajax({
            url:"notice/addNotice",
            type:"post",
          //  datatype:"json",
            data:{
                noticeTitle:$("#noticeTitle").val(),
                noticeContent:$("#noticeContent").val()
            },
            success:function(result){
              //  alert(result);
                if(result=="添加成功！"){
                    layer.msg('添加成功！', {
                        icon: 1,
                        time: 800,
                    },function () {
                        freshClose();
                    });
                }else {
                    layer.msg('添加失败!', {
                        icon: 0,
                        time: 800,
                    },function () {
                        freshClose();
                    });
                }

            }

        })
    }

    function freshClose() {
        window.parent.location.reload();//刷新父页面
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index)
    }
</script>
</body>
</html>